package com.jeegit.ecms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jeegit.common.annotation.Log;
import com.jeegit.common.enums.BusinessType;
import com.jeegit.ecms.domain.CmsVideoTeacher;
import com.jeegit.ecms.service.ICmsVideoTeacherService;
import com.jeegit.common.core.controller.BaseController;
import com.jeegit.common.core.domain.AjaxResult;
import com.jeegit.common.utils.poi.ExcelUtil;
import com.jeegit.common.core.page.TableDataInfo;

/**
 * 授课讲师Controller
 * 
 * @author jeegit
 * @date 2022-06-30
 */
@Controller
@RequestMapping("/ecms/teacher")
public class CmsVideoTeacherController extends BaseController
{
    private String prefix = "ecms/teacher";

    @Autowired
    private ICmsVideoTeacherService cmsVideoTeacherService;

    @RequiresPermissions("ecms:teacher:view")
    @GetMapping()
    public String teacher()
    {
        return prefix + "/teacher";
    }

    /**
     * 查询授课讲师列表
     */
    @RequiresPermissions("ecms:teacher:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsVideoTeacher cmsVideoTeacher)
    {
        startPage();
        List<CmsVideoTeacher> list = cmsVideoTeacherService.selectCmsVideoTeacherList(cmsVideoTeacher);
        return getDataTable(list);
    }

    /**
     * 导出授课讲师列表
     */
    @RequiresPermissions("ecms:teacher:export")
    @Log(title = "授课讲师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsVideoTeacher cmsVideoTeacher)
    {
        List<CmsVideoTeacher> list = cmsVideoTeacherService.selectCmsVideoTeacherList(cmsVideoTeacher);
        ExcelUtil<CmsVideoTeacher> util = new ExcelUtil<CmsVideoTeacher>(CmsVideoTeacher.class);
        return util.exportExcel(list, "授课讲师数据");
    }

    /**
     * 新增授课讲师
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存授课讲师
     */
    @RequiresPermissions("ecms:teacher:add")
    @Log(title = "授课讲师", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsVideoTeacher cmsVideoTeacher)
    {
        return toAjax(cmsVideoTeacherService.insertCmsVideoTeacher(cmsVideoTeacher));
    }

    /**
     * 修改授课讲师
     */
    @RequiresPermissions("ecms:teacher:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsVideoTeacher cmsVideoTeacher = cmsVideoTeacherService.selectCmsVideoTeacherById(id);
        mmap.put("cmsVideoTeacher", cmsVideoTeacher);
        return prefix + "/edit";
    }

    /**
     * 修改保存授课讲师
     */
    @RequiresPermissions("ecms:teacher:edit")
    @Log(title = "授课讲师", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsVideoTeacher cmsVideoTeacher)
    {
        return toAjax(cmsVideoTeacherService.updateCmsVideoTeacher(cmsVideoTeacher));
    }

    /**
     * 删除授课讲师
     */
    @RequiresPermissions("ecms:teacher:remove")
    @Log(title = "授课讲师", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsVideoTeacherService.deleteCmsVideoTeacherByIds(ids));
    }
}
